home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / BFLUSH.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  91 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)bflush.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10.  
  11. /* local headers */
  12. #include "blkio_.h"
  13.  
  14. /*man---------------------------------------------------------------------------
  15. NAME
  16.      bflush - flush a block file
  17.  
  18. SYNOPSIS
  19.      #include <blkio.h>
  20.  
  21.      int bflush(bp)
  22.      BLKFILE *bp;
  23.  
  24. DESCRIPTION
  25.      The bflush function causes any buffered data for the block file
  26.      associated with BLKFILE pointer bp to be written to the file and
  27.      the buffers to be emptied.  The header, if it has been modified,
  28.      is written out last.  The block file remains open.  If  bp is
  29.      open read-only or is not buffered, there will be no data to flush
  30.      and bflush will return a value of zero immediately.
  31.  
  32.      bflush should be called immediately before a block file is
  33.      unlocked.  lockb does this automatically.
  34.  
  35.      bflush will fail if one or more of the following is true:
  36.  
  37.      [EINVAL]       bp is not a valid BLKFILE pointer.
  38.      [BENOPEN]      bp is not open.
  39.  
  40. SEE ALSO
  41.      bexit, bputb, bsync.
  42.  
  43. DIAGNOSTICS
  44.      Upon successful completion, a value of 0 is returned.  Otherwise,
  45.      a value of -1 is returned, and errno set to indicate the error.
  46.  
  47. ------------------------------------------------------------------------------*/
  48. #ifdef AC_PROTO
  49. int bflush(BLKFILE *bp)
  50. #else
  51. int bflush(bp)
  52. BLKFILE *bp;
  53. #endif
  54. {
  55.     /* validate arguments */
  56.     if (!b_valid(bp)) {
  57.         errno = EINVAL;
  58.         return -1;
  59.     }
  60.  
  61.     /* check if not open */
  62.     if (!(bp->flags & BIOOPEN)) {
  63.         errno = BENOPEN;
  64.         return -1;
  65.     }
  66.  
  67.     /* check if not open for writing */
  68.     if (!(bp->flags & BIOWRITE)) {
  69.         return 0;
  70.     }
  71.  
  72.     /* check if not buffered */
  73.     if (bp->bufcnt == 0) {
  74.         return 0;
  75.     }
  76.  
  77.     /* synchronize file with buffers */
  78.     if (bsync(bp) == -1) {
  79.         BEPRINT;
  80.         return -1;
  81.     }
  82.  
  83.     /* empty the buffers */
  84.     if (b_initlist(bp) == -1) {
  85.         BEPRINT;
  86.         return -1;
  87.     }
  88.  
  89.     return 0;
  90. }
  91.